home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Serial I⁄O < prev    next >
Text File  |  1993-06-08  |  4KB  |  173 lines

  1. macro 'Open Serial Port [O]';
  2. begin
  3.   RequiresVersion(1.48);
  4.   OpenSerial('9600 baud,no parity,eight data,one stop');
  5. end;
  6.  
  7.  
  8. macro 'Put Serial [P]';
  9. begin
  10.    PutSerial(GetString('Enter a string:'));
  11. end;
  12.  
  13.  
  14. macro 'Serial Output Test [T]';
  15. var
  16.   i:integer;
  17. begin
  18.   SetCursor('Watch');
  19.   for i:=1 to 10 do
  20.     PutSerial('The is line ',i:3,chr(13),chr(10));
  21.   end;
  22. end;
  23.  
  24.  
  25. macro 'Get Serial and Echo [G]';
  26. var
  27.   i:integer;
  28.   ch:string; {actually one char}
  29. begin
  30.   ShowMessage('Press mouse button to abort.');
  31.   SetCursor('Watch');
  32.   repeat until GetSerial=''; {Flush input buffer}
  33.   repeat
  34.     ch:=GetSerial; {returns null string if input buffer empty}
  35.     if ch<>'' then ShowMessage('char="',ch,'" (',ord(ch):1,')');
  36.     PutSerial(ch);
  37.     if ch=chr(13) then PutSerial(chr(10)); {if return send line feed}
  38.   until button;
  39. end;
  40.  
  41.  
  42. macro 'Display Serial Input… [D]';
  43. {Displays serial input in a window.}
  44. var
  45.   x,y,width,height,count,line:integer;
  46.   ch:string; {actually one char}
  47.   BaudRate:string;
  48. begin
  49.   RequiresVersion(1.48);
  50.   repeat
  51.     BaudRate:=Getstring('Baud Rate(1200, 2400, 9600 or 19200)','9600');
  52.   until (BaudRate='1200') or (BaudRate='2400') or(BaudRate='9600') or (BaudRate='19200');
  53.   OpenSerial(BaudRate);
  54.   width:=500;
  55.   height:=500;
  56.   SetNewSize(width,height);
  57.   SetForeground(255);
  58.   SetBackground(0);
  59.   MakeNewWindow('Serial Input');
  60.   SetCursor('Watch');
  61.   SetFont('Monaco');
  62.   SetText('With background; Left Justified');
  63.   SetFontSize(9);
  64.   MoveTo(8,8);
  65.   count:=0;
  66.   line:=0;
  67.   ShowMessage('Press mouse button to abort');
  68.   repeat
  69.      ch:=GetSerial;
  70.      if ch<>'' then begin
  71.        count:=count+1;
  72.        if (ord(ch)=13) or (count=80) then begin {13=Carriage Return}
  73.          writeln(ch);
  74.          count:=0
  75.          line:=line+1;
  76.          if line=54 then begin
  77.            Clear;
  78.            moveto(8,8);
  79.            line:=0;
  80.          end;
  81.        end else
  82.          write(ch);
  83.      end;
  84.    until button;
  85. end;
  86.  
  87.  
  88. macro 'Capture Serial Input [C]';
  89. {
  90. Captures serial input and saves the characters a pixels in an image.
  91. The default image size of 200x200 allows up to 40,000 characters
  92. to be captured. The text can be exported(use 'Raw Data"), but you will
  93. need to change the file type to 'TEXT' to open it with a text editor.
  94. }
  95. var
  96.   x,y,width,height,cc,tc:integer;
  97.   ch:string; {actually one char}
  98. begin
  99.   RequiresVersion(1.48);
  100.   OpenSerial('9600');
  101.   width:=200;
  102.   height:=200;
  103.   SetNewSize(width,height);
  104.   MakeNewWindow('Serial Input');
  105.   SetPalette('Spectrum')
  106.   SetForeground(ord(' '));
  107.   Fill;
  108.   SetCursor('Watch');
  109.   cc:=0; tc:=0;
  110.   ShowMessage('Use command-period to abort');
  111.   for y:=0 to height-1 do begin
  112.     for x:=0 to width-1 do begin
  113.       repeat tc:=tc+1; ch:=GetSerial until ch<>'';
  114.       PutPixel(x,y,ord(ch));
  115.       cc:=cc+1;
  116.     end;
  117.     ShowMessage(tc:6,'  ',cc:6);
  118.   end;
  119. end;
  120.  
  121.  
  122. procedure GetResponse;
  123. {Gets responses to commands sent to the Newport 2-axis controller}
  124. var
  125.   ch:string;
  126.   TimeOutTicks:integer;
  127.   TimeOUt:boolean;
  128. begin
  129.   response:='';
  130.   TimeOutTicks:=TickCount+60; {1 sec.}
  131.   repeat
  132.     ch:=GetSerial;
  133.     if ord(ch)>=32 {ignore control characters}
  134.       then response:=concat(response,ch);
  135.     timeout:=TickCount>TimeOutTicks;
  136.   until (ch=return) or TimeOut;
  137.   if TimeOut then response:=concat(response,'[1 second time out]');
  138. end;
  139.  
  140.  
  141. macro 'Test Newport Motion Controller…[N]';
  142. {
  143. Simple macro to test the Newport PMC200-P programmable 2-axis
  144. motion controller. Before starting, connect the PMC200-P to 
  145. the Mac's modem port. This can be done using a modem cable
  146. and a 9-pin to 25-pin adapter consisting of a female 25-pin
  147. connector wired back-to-back with a female 9-pin connector
  148. acording to the table below.
  149.  
  150.    9-pin      25-pin
  151.      2 <------> 3  (receive data)
  152.      3 <------> 2  (transmit data)
  153.      5 <------> 7  (signal ground)
  154.  
  155. Note: RS-232 INPUT ECHO MODE must be disabled. The phone
  156. number for Newport is 714-253-1665.
  157. }
  158. var
  159.   cmd,response,linefeed,return:string;
  160. begin
  161.   RequiresVersion(1.48);
  162.   linefeed:=chr(10);
  163.   return:=chr(13);
  164.   OpenSerial('9600 baud,no parity,eight data,one stop');
  165.   repeat
  166.     cmd:=GetString('Enter PMC200-P Command:','*IDN?');
  167.     repeat until GetSerial=''; {flush input buffer}
  168.     PutSerial(cmd,return,linefeed);
  169.     GetResponse;
  170.     PutMessage(response)
  171.   until button;
  172. end;
  173.